# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=ocaml-lablgtk3
_pkgname=lablgtk
pkgver=3.1.2
pkgrel=3
pkgdesc="OCaml interface to GTK+3"
provides="$pkgname-sourceview3=$pkgver-r$pkgrel"
url="https://github.com/garrigue/lablgtk"
arch="all !riscv64 !loongarch64" # ocaml
license="LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-cairo2-dev
	gtksourceview-dev
	"
makedepends="$depends_dev dune dune-configurator ocaml"
options="!check"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/garrigue/lablgtk/archive/$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build \
		-p lablgtk3,lablgtk3-sourceview3 \
		--verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit \
		lablgtk3 lablgtk3-sourceview3
	rm -Rf "$pkgdir"/.omit
}

dev() {
	provides="$pkgname-sourceview3-dev=$pkgver-r$pkgrel"

	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
c63a492160f36685f65cb6bc0e72ff4939005acb2c65c56c0d9ba8f2112a618f24db84765e7b4416e49024048a36895028cfc5ef2c3e298dd4a309e902e34af5  ocaml-lablgtk3-3.1.2.tar.gz
"
